/*
package com.example.forum.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springbootmybatis.commons.annotations.UncheckToken;
import com.example.springbootmybatis.commons.authrization.TokenManager;
import com.example.springbootmybatis.commons.tools.StringUtil;
import com.example.springbootmybatis.commons.tools.Transfer.DataTransfer;
import com.example.springbootmybatis.entity.TProduct;
import com.example.springbootmybatis.service.ITProductService;
import com.example.springbootmybatis.vo.JsonResult;
import com.example.springbootmybatis.vo.ProductModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

*/
/**
 * <p>
 * 控制器
 * </p>
 *
 * @author LiuCheng
 * @since 2019-12-04
 *//*

@RestController
@Api(tags = "商品控制层")
@RequestMapping("/Product")
public class TProductController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(com.example.springbootmybatis.controller.TProductController.class);

    @Autowired //注入service
    private ITProductService productService;

    @Autowired
    DataTransfer dataTransfer;

    @Autowired
    private TokenManager tokenManager;


    @UncheckToken
    @ApiOperation(value = "添加")
    @PostMapping(value = "/create")
    public JsonResult create(
            @Valid @RequestBody @ApiParam(name = "数据对象", value = "传入json格式", required = true) ProductModel model) {
        LOGGER.info("添加商品");
        var dto = new TProduct();
        dto = (TProduct) dataTransfer.getObjectFromObject(dto, model);
        dto.setCreatorUserId(currentUserId());
        productService.save(dto);
        return new JsonResult(HttpStatus.OK, "创建成功", null);
    }

    @UncheckToken
    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public JsonResult delete(String id) {
        var product = productService.getById(id);
        if (product == null)
            return new JsonResult(HttpStatus.NOT_FOUND, "该数据不存在", null);
        product.setIsdeleted(true);
        product.setDeleterUserId(currentUserId());
        productService.updateById(product);
        return new JsonResult(HttpStatus.OK, "删除成功", null);
    }


    @UncheckToken
    @ApiOperation(value = "更新")
    @PostMapping(value = "/update")
    public JsonResult update(
            @Valid @RequestBody @ApiParam(name = "数据对象", value = "传入json格式", required = true) ProductModel model) {

        if (StringUtil.isEmpty(model.getId())) {
            return new JsonResult(HttpStatus.BAD_REQUEST, "商品id不能为空", null);
        }

        var product = productService.getById(model.getId());
        if (product == null)
            return new JsonResult(HttpStatus.NOT_FOUND, "该数据不存在", null);

        product = (TProduct) dataTransfer.getObjectFromObject(product, model);
        productService.updateById(product);
        return new JsonResult(HttpStatus.OK, "更新成功", null);
    }


    @UncheckToken
    @ApiOperation(value = "获取单条商品")
    @RequestMapping(value = "/getProduct", method = {RequestMethod.GET})
    public JsonResult getProduct(String id) {
        var product = productService.getById(id);
        if (product == null) {
            return new JsonResult(HttpStatus.NOT_FOUND, "该数据不存在", null);
        }
        return new JsonResult(HttpStatus.OK, "成功", product);
    }


    @ApiOperation(value = "获取商品列表")
    @RequestMapping(value = "/getProductPaged", method = {RequestMethod.GET})
    public JsonResult getProductPaged(String name, String code, Integer pageIndex, Integer pageSize) {
        Page<TProduct> page = new Page<>(pageIndex, pageSize);
        var queryWrapper = new QueryWrapper<TProduct>()
                .eq(!StringUtil.isEmpty(code), "code", code)
                .like(!StringUtil.isEmpty(name), "name", name)
                .eq("isdeleted", 0)
                .orderByDesc("creationtime");

        var list = productService.page(page, queryWrapper);
        return new JsonResult(HttpStatus.OK, "成功", list);
    }


    @UncheckToken
    @ApiOperation(value = "获取商品列表-多表联合查询")
    @RequestMapping(value = "/getProductPagedExtend", method = {RequestMethod.GET})
    public JsonResult getProductPagedExtend(String name, String code,  Integer pageIndex, Integer pageSize) {
        Page<Object> page = new Page(pageIndex, pageSize);
        //自定义service
        var list = productService.getProductPagedExtend(page, name, code);
        return new JsonResult(HttpStatus.OK, "成功", list);
    }
}
*/
